<!DOCTYPE html>
<html lang="cn-zh">

<head>
  
  <meta charset="utf-8">



<meta name="viewport" content="width=device-width, initial-scale=1.0">


  
    <meta name="description" content="安装 apt-get install supervisor 使用说明 supervisor配置文件：/etc/supervisor/supervisord.conf 子进程配置文件路径：/etc/supervisor/conf.d/
常用命令说明 # 查看所有进程的状态 supervisorctl status # 停止iot supervisorctl stop iot # 启动iot supervisorctl start iot # 重启iot supervisorctl restart iot # 配置文件修改后使用该命令加载新的配置 supervisorctl update # 重新启动配置中的所有程序 supervisorctl reload 配置GO进程 [program:iot] # 脚本目录 directory=/opt/iot # 脚本执行命令 command=/opt/iot/main # 日志输出 stdout_logfile=/opt/iot/supervisor/main.log # supervisor启动的时候是否随着同时启动，默认True autostart=true autorestart=true startsecs=5 priority=1 stopasgroup=true killasgroup=true 常见问题 unix:///var/run/supervisor.sock no such file 问题描述：安装好supervisor没有开启服务直接使用supervisorctl报的错
解决办法：supervisord -c /etc/supervisord.conf
command中指定的进程已经起来，但supervisor还不断重启 问题描述：command中启动方式为后台启动，导致识别不到pid，然后不断重启，这里使用的是elasticsearch，command指定的是$path/bin/elasticsearch -d
解决办法：supervisor无法检测后台启动进程的pid，而supervisor本身就是后台启动守护进程，因此不用担心这个
启动了多个supervisord服务，导致无法正常关闭服务 问题描述：在运行supervisord -c /etc/supervisord.">
  


<meta name="color-scheme" content="light dark">







<meta name="generator" content="Hugo 0.111.2">

<meta content="" name="keywords">
<meta content="Supervisor管理GO程序 - 通通不同-博客" property="og:title">
<meta content="开发的乐趣在于相通而不同 - " property="og:description">

<meta name="msvalidate.01" content="F56ED94B7E86941E3DACEF208F07D329" />

  <title>
    
    Supervisor管理GO程序
     - 通通不同-博客
    
</title>

  <link rel="canonical" href="https://codebeautiful.gitee.io/post/supervisor/">


  








  
    
  
  
  <link rel="stylesheet" href="/css/base.min.4f231885947d13c748c815d93da49f07ab89afb67629f9970b7c054610e88e0b.css" integrity="sha256-TyMYhZR9E8dIyBXZPaSfB6uJr7Z2KfmXC3wFRhDojgs=" crossorigin="anonymous">



</head>

<body>
  <nav class="u-background">
  <div class="u-wrapper">
    <ul class="Banner">
      <li class="Banner-item Banner-item--title">
        <h1 class="Banner-heading">
          <a class="Banner-link u-clickable" href="/">通通不同-博客</a>
        </h1>
      </li>
      
        <li class="Banner-item">
          <a class="Banner-link u-clickable" href="/post/">全部</a>
        </li>
      
        <li class="Banner-item">
          <a class="Banner-link u-clickable" href="/categories/">分类</a>
        </li>
      
        <li class="Banner-item">
          <a class="Banner-link u-clickable" href="/tags/">标签</a>
        </li>
      
        <li class="Banner-item">
          <a class="Banner-link u-clickable" href="/about/">关于</a>
        </li>
      
    </ul>
  </div>
</nav>

  <main>
    <div class="u-wrapper">
      <div class="u-padding">
        

  <article>
    <header class="Heading">
  <h2 class="Heading-title">
    <a class="Heading-link u-clickable" href="/post/supervisor/" rel="bookmark">Supervisor管理GO程序</a>
  </h2>
  
    <time datetime="2023-03-21T14:04:34&#43;08:00">21 March, 2023</time>
  
</header>

    <h3 id="安装">
  <a class="Heading-link u-clickable" href="/post/supervisor/#%e5%ae%89%e8%a3%85">安装</a>
</h3>

<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>apt-get install supervisor</span></span></code></pre></div>
<h3 id="使用说明">
  <a class="Heading-link u-clickable" href="/post/supervisor/#%e4%bd%bf%e7%94%a8%e8%af%b4%e6%98%8e">使用说明</a>
</h3>
<p>supervisor配置文件：/etc/supervisor/supervisord.conf
子进程配置文件路径：/etc/supervisor/conf.d/</p>
<h3 id="常用命令说明">
  <a class="Heading-link u-clickable" href="/post/supervisor/#%e5%b8%b8%e7%94%a8%e5%91%bd%e4%bb%a4%e8%af%b4%e6%98%8e">常用命令说明</a>
</h3>

<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># 查看所有进程的状态</span>
</span></span><span style="display:flex;"><span>supervisorctl status
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 停止iot</span>
</span></span><span style="display:flex;"><span>supervisorctl stop iot
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 启动iot</span>
</span></span><span style="display:flex;"><span>supervisorctl start iot
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 重启iot</span>
</span></span><span style="display:flex;"><span>supervisorctl restart iot
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 配置文件修改后使用该命令加载新的配置</span>
</span></span><span style="display:flex;"><span>supervisorctl update
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 重新启动配置中的所有程序</span>
</span></span><span style="display:flex;"><span>supervisorctl reload</span></span></code></pre></div>
<h3 id="配置go进程">
  <a class="Heading-link u-clickable" href="/post/supervisor/#%e9%85%8d%e7%bd%aego%e8%bf%9b%e7%a8%8b">配置GO进程</a>
</h3>

<pre tabindex="0"><code class="language-conf" data-lang="conf">[program:iot]
# 脚本目录
directory=/opt/iot
# 脚本执行命令
command=/opt/iot/main
# 日志输出
stdout_logfile=/opt/iot/supervisor/main.log
# supervisor启动的时候是否随着同时启动，默认True
autostart=true
autorestart=true
startsecs=5
priority=1
stopasgroup=true
killasgroup=true</code></pre>
<h3 id="常见问题">
  <a class="Heading-link u-clickable" href="/post/supervisor/#%e5%b8%b8%e8%a7%81%e9%97%ae%e9%a2%98">常见问题</a>
</h3>
<ol>
<li>unix:///var/run/supervisor.sock no such file</li>
</ol>
<blockquote>
<p>问题描述：安装好supervisor没有开启服务直接使用supervisorctl报的错</p>
</blockquote>
<blockquote>
<p>解决办法：supervisord -c /etc/supervisord.conf</p>
</blockquote>
<ol start="2">
<li>command中指定的进程已经起来，但supervisor还不断重启</li>
</ol>
<blockquote>
<p>问题描述：command中启动方式为后台启动，导致识别不到pid，然后不断重启，这里使用的是elasticsearch，command指定的是$path/bin/elasticsearch -d</p>
</blockquote>
<blockquote>
<p>解决办法：supervisor无法检测后台启动进程的pid，而supervisor本身就是后台启动守护进程，因此不用担心这个</p>
</blockquote>
<ol start="3">
<li>启动了多个supervisord服务，导致无法正常关闭服务</li>
</ol>
<blockquote>
<p>问题描述：在运行supervisord -c /etc/supervisord.conf之前，直接运行过supervisord -c /etc/supervisord.d/xx.conf导致有些进程被多个superviord管理，无法正常关闭进程。</p>
</blockquote>
<blockquote>
<p>解决办法：使用ps -fe | grep supervisord查看所有启动过的supervisord服务，kill相关的进程。</p>
</blockquote>

    


  

  

  





  <footer>
    
      
    
      
    
      
        <ul class="Tags">
          
            <li class="Tags-item u-background">
              <a class="Tags-link u-clickable" href="/tags/supervisor/" rel="tag">Supervisor</a>
            </li>
          
            <li class="Tags-item u-background">
              <a class="Tags-link u-clickable" href="/tags/go%E7%9A%84%E5%AE%88%E6%8A%A4%E8%BF%9B%E7%A8%8B%E7%AE%A1%E7%90%86/" rel="tag">GO的守护进程管理</a>
            </li>
          
        </ul>
      
    
  </footer>

    
  

  </article>


      </div>
    </div>
  </main>
  
  <footer class="Footer">
    <div class="u-wrapper">
      <div class="u-padding">
        开发的乐趣在于相通而不同
      </div>
    </div>
  </footer>


  <script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?d08a2ad355cb7a065a41be081b43297e";
  var s = document.getElementsByTagName("script")[0];
  s.parentNode.insertBefore(hm, s);
})();
</script>

</body>

</html>
